import {Component} from 'react'

function withMouse(WrappedComponent){

  return class extends Component{
        constructor(props){
            super(props);
            this.state={
                x:0,
                y:0
            }
        }
        handleMouseMove=(e)=>{
           this.setState({
               x:e.clientX,
               y:e.clientY
           })
        }

        componentDidMount(){
            window.addEventListener("mousemove",this.handleMouseMove)
        }
        componentWillUnmount(){
            window.removeEventListener("mousemove")
        }

       render(){
        return(<WrappedComponent {...this.state}></WrappedComponent>)
       }  
    }
}

export {withMouse}  